package com.anjoyo.xgh.musicshare.activity;


import m.framework.ui.widget.slidingmenu.SlidingMenu;

import com.anjoyo.xgh.musicshare.R;
import com.anjoyo.xgh.musicshare.adapter.SlidingAdapter;
import com.anjoyo.xgh.musicshare.pageview.HomePage;
import com.anjoyo.xgh.musicshare.util.MusicSpf;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class HomeActivity extends Activity {
	Context con=this;
	Intent intent;
	long id;
	String username;
	SlidingMenu menu;
	public static SlidingAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 menu=new SlidingMenu(this);
		 menu.setMenuItemBackground(R.color.sliding_menu_item_down, R.color.sliding_menu_item_release);
			menu.setMenuBackground(R.color.sliding_menu_background);
			menu.setTtleHeight(44);
			menu.setBodyBackground(R.color.sliding_menu_body_background);
			menu.setShadowRes(R.drawable.sliding_menu_right_shadow);
			menu.setMenuDivider(R.drawable.sliding_menu_sep);
			adapter = new SlidingAdapter(menu,this);
			menu.setAdapter(adapter);
			setContentView(menu);
			menu.triggerItem(SlidingAdapter.GROUP_CHOOSE, SlidingAdapter.ITEM_HOME);
			if (MusicSpf.getloginUser(this)==null) {
			startActivity(new Intent(con, LoginAct.class));
			HomeActivity.this.finish();
		}
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		adapter.homepage.getdata();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (!menu.isMenuShown()) {
				menu.showMenu();
				Toast.makeText(con, "再按一次，退出程序", 0).show();
				return false;
			}else {
				finish();
			}
		}
		return super.onKeyDown(keyCode, event);
	}
}
